package com.exchange.controller;

import com.exchange.service.AnalyticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/dashboard")
@CrossOrigin(origins = "*")
@PreAuthorize("hasRole('MERCHANT') or hasRole('ADMIN')")
public class DashboardController {
    
    @Autowired
    private AnalyticsService analyticsService;
    
    // Get merchant dashboard data
    @GetMapping("/merchant")
    public ResponseEntity<Map<String, Object>> getMerchantDashboard() {
        // In a real implementation, we'd get the current merchant's ID from the security context
        // For now, using a placeholder
        Long currentMerchantId = 1L; // Placeholder - should come from security context
        Map<String, Object> dashboardData = analyticsService.getMerchantDashboard(currentMerchantId);
        return ResponseEntity.ok(dashboardData);
    }
    
    // Get order analytics for the merchant
    @GetMapping("/analytics/orders")
    public ResponseEntity<Map<String, Object>> getOrderAnalytics() {
        // In a real implementation, we'd get the current merchant's ID from the security context
        // For now, using a placeholder
        Long currentMerchantId = 1L; // Placeholder - should come from security context
        Map<String, Object> analytics = analyticsService.getOrderAnalytics(currentMerchantId);
        return ResponseEntity.ok(analytics);
    }
    
    // Get other analytics as needed
    @GetMapping("/analytics/products")
    public ResponseEntity<?> getProductAnalytics() {
        // Placeholder for product analytics
        return ResponseEntity.ok(Map.of("message", "Product analytics endpoint"));
    }
}